package selenium.demo;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

/**
 * @Author quan
 * @Description 等待：显示等待、隐式等待、强制等待
 * @Date 2023/8/14 11:57
 */


public class Demo5_Wait {
    public static void main(String[] args) throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com/");
        //1-首先输入“音乐”
        //找到输入框输入音乐-找到百度一下按钮并点击
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("音乐");
        webDriver.findElement(By.cssSelector("#su")).click();
        //2-智能等待
//        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);//表示等待3s
        //2-强制等待
//        sleep(1000);
        //2-显示等待
        // 显示等待5s
        WebDriverWait wait = new WebDriverWait(webDriver, 5);
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#kw")));

        //3-找到输入框-清除该内容
        webDriver.findElement(By.cssSelector("#kw")).clear();
        //4-退出
        webDriver.quit();
    }
}
